package pers.whj.util.tree;

/**
 * use this visitor to visit any element in this tree
 *
 * @param <T> the type of element
 */
public interface TreeVisitor<T> {
    /**
     * if current node exists
     *
     * @return true if it exists
     */
    boolean exist();

    /**
     * if current node has left child
     *
     * @return true if it has or false
     */
    boolean existLeft();

    /**
     * if current node has right child
     *
     * @return true if it has or false
     */
    boolean existRight();

    /**
     * if this node has parent node
     *
     * @return true if it has
     */
    boolean existParent();

    /**
     * get the data of current node
     *
     * @return the element
     */
    T get();

    /**
     * get the data of left child
     *
     * @return data
     */
    T getLeft();

    /**
     * get the data of right child
     *
     * @return data
     */
    T getRight();

    /**
     * step to the left child
     */
    void left();

    /**
     * step to the right child
     */
    void right();

    /**
     * step to the left child but not record the parent node
     */
    void leftNotRecord();

    /**
     * step to the left child but not record the parent node
     */
    void rightNotRecord();

    /**
     * step to the left child and get the data
     *
     * @return the left child
     */
    T leftAndGet();

    /**
     * step to the right child and get the data
     *
     * @return the right child
     */
    T rightAndGet();

    /**
     * the height of current node
     *
     * @return height
     */
    int height();

    /**
     * back to the parent of current node
     *
     * @return if there is a parent, back and return true
     */
    boolean stepBack();

    /**
     * back to the parent of current node, not pop the parent node out of stack
     *
     * @return parent node
     */
    boolean stepBackNotPop();

    /**
     * step back the specified steps
     *
     * @param steps steps to back
     * @return true if success
     */
    boolean stepBack(int steps);

    /**
     * reset to the root node
     */
    void reset();
}